<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/component.css">
</head>
<body>
<!-- All modals added here for the demo. You would of course just have one, dynamically created -->

<div class="md-modal md-effect-19" id="modal-19">
    <div class="md-content">
        <h3>Modal Dialog</h3>
        <div>
            <p>This is a modal window. You can do the following things with it:</p>
            <ul>
                <li><strong>Read:</strong> modal windows will probably tell you something important so don't forget to read what they say.</li>
                <li><strong>Look:</strong> a modal window enjoys a certain kind of attention; just look at it and appreciate its presence.</li>
                <li><strong>Close:</strong> click on the button below to close the modal.</li>
            </ul>
            <button name="alertClose" class="md-close button">Close me!</button>
        </div>
    </div>
</div>


        <div >
            <button class="md-trigger md-setperspective" data-modal="modal-19">Slip from top</button>
        </div>
<!--dom结构部分-->
<div id="uploader-demo">
    <!--用来存放item-->
    <div id="fileList" class="uploader-list"></div>
    <div id="filePicker">选择图片</div>
</div>
<!--<div class="md-overlay"></div>&lt;!&ndash; the overlay element &ndash;&gt;-->

<!-- classie.js by @desandro: https://github.com/desandro/classie -->
<script type="text/javascript" src="js/lib/jquery-1.12.0.js"></script>


</body>


<script type="text/javascript"
        src="js/lib/webuploader.html5only.js"></script>

<script type="text/javascript">
    $(function() {

        function init() {

            var overlay = $( '.md-overlay' );

            //[].slice.call( document.querySelectorAll( '.md-trigger' ) ).forEach( function( el, i ) {
            var el =$(".md-trigger");
            var i =19;
            var modal = $( '#' + el.attr( 'data-modal' ) ),
                    close = modal.find( '[name=alertClose]' );



            function removeModalHandler() {
                modal.removeClass('md-show' );
                $( ".md-setperspective.md-trigger").removeClass("md-setperspective") ;
            }

            el.click(function( ) {
                modal.addClass('md-show' );
                overlay.unbind("click", removeModalHandler );
                overlay.bind( "click",removeModalHandler );

                if( el.hasClass("md-setperspective") ) {
                    setTimeout( function() {
                        $(document.documentElement).addClass('md-perspective' );
                    }, 25 );
                }
            });

            close.click(function( ev ) {
                ev.stopPropagation();
                removeModalHandler();
            });

            //} );

        }

        init();

    });
    $(document).ready(function()
    {
        var $list = $("#fileList"),thumbnailWidth="20px",thumbnailHeight = "20px";
        // 初始化Web Uploader
        var uploader = WebUploader.create({

            // 选完文件后，是否自动上传。
            auto: true,

            // swf文件路径
//            swf:  '/js/Uploader.swf',

            // 文件接收服务端。
            server: 'php/index.php?m=User&a=login',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#filePicker',

            // 只允许选择图片文件。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });
        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                            '<div id="' + file.id + '" class="file-item thumbnail">' +
                            '<img>' +
                            '<div class="info">' + file.name + '</div>' +
                            '</div>'
                    ),
                    $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, thumbnailWidth, thumbnailHeight );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                    $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                        .appendTo( $li )
                        .find('span');
            }

            $percent.css( 'width', percentage * 100 + '%' );
        });

// 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file ) {
            $( '#'+file.id ).addClass('upload-state-done');
        });

// 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                    $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

// 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });
</script>
</html>